package org.sbi.satvik.action;

import java.io.InputStream;
import java.io.StringBufferInputStream;

import org.sbi.satvik.beans.SearchDataBean;
import org.sbi.satvik.beans.User;
import org.sbi.satvik.model.Login;
import org.sbi.satvik.model.SaveFormDataModel;
import org.sbi.satvik.model.SearchDataModel;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class FormDataAction extends ActionSupport implements ModelDriven<SearchDataBean>{
	
	private static SearchDataBean searchDataBean = new SearchDataBean();
	
	private InputStream inputStream;
	
	private String dataToSave;
	private String userName;
	private String password;

	/*private String startDate;
	private String endDate;
	private String aplicantName;
	private String lastName;*/

	/**
	 * for adding data asction
	 * 
	 * @return
	 */
	@SuppressWarnings("deprecation")
	public String dataAdd() {

		System.out.println(dataToSave);

		inputStream = new StringBufferInputStream(
				SaveFormDataModel.saveFormData(getDataToSave()));

		return SUCCESS;

	}

	public String login() {

		User user = new User();
		user.setName(getUserName());
		user.setPassword(getPassword());

		inputStream = new StringBufferInputStream(Login.authenticate(user));

		return SUCCESS;

	}

	public String loginRagistration() {

		User user = new User();
		user.setName(getUserName());
		user.setPassword(getPassword());

		inputStream = new StringBufferInputStream(Login.loginReg(user));
		return SUCCESS;
	}

	public String getSearchData() {

		inputStream = new StringBufferInputStream(SearchDataModel.getSerachData(searchDataBean));

		
		return SUCCESS;
	}
	
	/**
	 *  Setter Getter
	 */
	public InputStream getInputStream() {
	    return inputStream;
	}
	
	public String getDataToSave() {
		return dataToSave;
	}

	public void setDataToSave(String dataToSave) {
		this.dataToSave = dataToSave;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	} 
	
	/*public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public String getAplicantName() {
		return aplicantName;
	}

	public void setAplicantName(String aplicantName) {
		this.aplicantName = aplicantName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}*/

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	/**
	 * END
	 */

	@Override
	public SearchDataBean getModel() {
		// TODO Auto-generated method stub
		return searchDataBean;
	}
}
